/**
 * Created by Administrator on 2017/4/20 0020.
 */
var CoverPiece={
    create:function (url,_w,_h,_idx) {
        var cp={};
        cp.ui=new PIXI.DisplayObjectContainer();
        cp.ui.pivot.x=_w/2;
        cp.ui.pivot.y=_h/2;
        cp.idx=_idx;

        var con=new PIXI.DisplayObjectContainer();
        cp.ui.addChild(con);
        var sp=Easy.CreateSprite(url+'.png',0,0,0.5,0.5,1);
        con.addChild(sp);
        var mask=new PIXI.Graphics();
        mask.beginFill(0xff0000,1);
        mask.drawRect(0,0,_w,_h);
        mask.endFill();
        con.addChild(mask);
        sp.mask=mask;
        con.interactive=true;
        con.blendMode=PIXI.BLEND_MODES.MULTIPLY;

        var bool_move;
        var bool_down;
        var downX;
        var detalX;
        con.on('pointerdown',function (e) {
            //e.data.originalEvent.stopImmediatePropagation();

            if(bool_click)
            {
                bool_down=true;
                downX=e.data.global.x;
                detalX=0;
            }

        })
        con.on('pointermove',function (e) {

            if(bool_click)
            {
                if(bool_down)
                {
                    detalX=e.data.global.x-downX;
                }
            }
        })
        con.on('pointerup',function (e) {
            bool_down=false;
            if(bool_click)
            {
                if (Math.abs(detalX)<1)
                {
                    document.dispatchEvent(new CustomEvent('Game_BigIn',{'detail':url+'_b.png'}))
                }
            }
        })

        var con_reflect=new PIXI.DisplayObjectContainer();
        cp.ui.addChildAt(con_reflect,0);
        con_reflect.alpha=0.1;
        con_reflect.y=780;
        con_reflect.scale.y=-1;

        var sp_re=Easy.CreateSprite(url+'.png',0,0,0.5,0.5,1);
        con_reflect.addChild(sp_re);
        var mask_re=new PIXI.Graphics();
        mask_re.beginFill(0xff0000,1);
        mask_re.drawRect(0,0,_w,_h);
        mask_re.endFill();
        con_reflect.addChild(mask_re);
        sp_re.mask=mask_re;


        fit(sp,_w,_h,sp.width,sp.height,0,0);
        fit(sp_re,_w,_h,sp_re.width,sp_re.height,0,0);

        function fit(video,StageWidth, StageHeight, loadvideowidth, loadvideoheight) {
            if ((loadvideowidth / loadvideoheight) > (StageWidth / StageHeight))
            {
                video.width = StageHeight * ((loadvideowidth / loadvideoheight));
                video.height = StageHeight;
                video.y = 0 + video.height/2;
                video.x = -Math.abs((video.width - StageWidth) / 2) + video.width/2;
            }
            else if ((loadvideowidth / loadvideoheight) < (StageWidth / StageHeight))
            {
                video.width = StageWidth;
                video.height = StageWidth * (loadvideoheight / loadvideowidth);
                video.x = 0 + video.width/2;
                video.y = -(Math.abs(video.height - StageHeight) / 2) + video.height/2;
            }
            else if ((loadvideowidth / loadvideoheight) == (StageWidth / StageHeight))
            {
                video.width = StageWidth;
                video.height = StageHeight;
                video.x = video.width/2;
                video.y = video.height/2;
            }
        }

        return cp;
    }
}